<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="Public/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="Public/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link href="Public/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet">
	    <link rel="shortcut icon" href="Public/Admin/Flat/img/favicon.ico">
	    <!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
	    <!--[if lt IE 9]>
	      <script src="dist/js/vendor/html5shiv.js"></script>
	      <script src="dist/js/vendor/respond.min.js"></script>
	    <![endif]-->
	    <!--<script type="text/javascript" src="Public/Admin/jquery-1.9.1.min.js"></script>-->
	    <script type="text/javascript" src="Public/Admin/jquery-1.8.2.min.js"></script>
	    <!--载入百度编辑器-->
    	<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.config.js"></script>
		<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.all.min.js"> </script>
		<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
    	<!--uploadify-->
    	<script type="text/javascript" src="Public/uploadify/jquery.uploadify.min.js"></script>
    	<link rel="stylesheet" type="text/css" href="Public/uploadify/uploadify.css">
	    <style type="text/css">
	    	ul,ol,li{list-style: none;}
	    	.w160{width:160px;}
	    	.w200{width:200px;}
	    	.w900{width:900px;}
	    	.fw{font-weight: bold; font-size: 16px;}
	    	.hide{overflow: hidden;}
	    	body{margin-bottom: 100px;}
	    	#uploadList2 li{float: left;margin-right:10px;}
	    </style>
	    <script type="text/javascript" charset="utf-8">
	    	$(function(){
	    		$("[name=gcategory_cate_id]").change(function(){//alert(1);
	    			//抓取元素
					var fid = $('option:selected').attr('fid');
					//给隐藏域赋值
					$('[name=form_fid]').val(fid);
					//发送异步
    				$.ajax({
    					type:"post",
    					url:"{{U('Goods/ajax_typeAttr')}}",
    					data:{id:fid},
    					dataType:'json',
    					success:function(phpData){//请求之后，响应成功执行
    						//属性（不可选）
    						var Attr = '';
    						//规格（可选）
    						var Spec = '';
    						//document.write(phpData);
    						$.each(phpData,function(k,v){
    							if(v.fattr_type==1){//属性
    								Attr += '<tr class="info">'+
    										'<td class="w160">'+ v.fattr_name +'</td>'+
    										'<td>'+
    										'<select name="arr['+v.fa_id+']"><option value="">请选择</option>';
    								$.each(v.fattr_value,function(kk,vv){
    									Attr += '<option value="'+ vv +'">'+ vv +'</option>';	
    								});
    								Attr += '</select></td></tr>';
    								//document.write(Attr);
    							}
    							else{//规格
    								Spec += '<tr class="info">'+
    										'<td class="w160">'+ v.fattr_name +'</td>'+
    										'<td>'+
    										'<select name="spec['+v.fa_id+'][value][]"><option value="">请选择</option>';
    								$.each(v.fattr_value,function(kk,vv){
    									Spec += '<option value="'+ vv +'">'+ vv +'</option>';	
    								});
    								Spec += '</select></td>';
    								Spec += '<td>附加价格：<input type="text" name="spec['+v.fa_id+'][attr_price][]" /></td>';
    								Spec += '<td><span class="btn btn-success add-spec">增加规格</span></td>';
    								Spec += '</tr>';
    								//document.write(Spec);
    							}
    						});
    					    //插入属性
		    				$('#attr').html(Attr);
		    				$('#spec').html(Spec);
    					}
    				});
  				     
	    		})
	    		
	    		//添加规格
	   			$(".add-spec").live('click',function(){
					var parentTr = $(this).parents('tr');
					//克隆
					var cloneTr = parentTr.clone();
					cloneTr.find('.add-spec').removeClass('btn-success add-spec').addClass('btn-danger remove-spec').html('删除规格');
					//插入到下一行
					parentTr.after(cloneTr);
					
	    		})
	    		//删除规格
	    		$(".remove-spec").live('click',function(){
	    			$(this).parents('tr').remove();
	    		})

	    	})
	    </script>
	</head>
	<body>
		<!--页面导航-->
		<div class="alert alert-success" role="alert">
			商品管理&nbsp;>&nbsp;编辑商品
		</div>
		<p>
			<a href="{{U('Good/index')}}" class="btn btn-info btn-sm">返回</a>
		</p>
		<form action="" method="post" enctype="multipart/form-data">
			<table class="table table-hover">
				<tr>
					<td style="width:200px;">所属分类</td>
					<td>
						<select name="gcategory_cate_id" id="gcategory_cate_id" class="form-control w200">
							<option value="">-请选择-</option>
							{{foreach from="$gcateData" value="$v"}} {{$v['cate_id']}}
							<option fid="{{$v['form_fid']}}" value="{{$v['cate_id']}}" {{if value=" $oldData['gcategory_cate_id'] eq $v['cate_id']" }}  selected="selected" {{endif}}>{{$v['_name']}}</option>
							{{endforeach}}
						</select>
					</td>
				</tr>
			</table>
	
			{{foreach from="$arr" key="$k" value="$v"}}

			<p class="btn btn-primary btn-sm fw mb20">{{if value="$k eq 1"}}商品属性{{else}}商品规格{{endif}}</p>
			<table class="table table-hover" {{if value="$k == 1"}}id="attr"{{else}}id="spec"{{endif}}>
			{{if value="$k == 1"}}
				{{foreach from="$v" value="$vv"}}
				<tr class="info">
					<td class="w160">{{$vv['fattr_name']}}</td>
					<td>
						<select name="arr[{{$vv['fa_id']}}]">
							<option value="">请选择</option>
							{{foreach from="$vv[fattr_value]" value="$val"}}
							 <option value="{{$val}}" {{if value="$vv['ga_value'] eq $val"}}selected{{endif}}>{{$val}}</option>
							{{endforeach}}
						</select>
					</td>
				</tr>
				{{endforeach}}
				{{else}}
				{{foreach from="$v" value="$vv"}}
				<tr class="info">
					<td class="w160">{{$vv['fattr_name']}}</td>
					<td>
						<select name="arr[{{$vv['fa_id']}}]">
							<option value="">请选择</option>
							{{foreach from="$vv['fattr_value']" key="$key" value="$val"}}
							 <option value="{{$val}}" {{if value="$vv['ga_value'] eq $val"}}selected{{endif}}>{{$val}}</option>
							{{endforeach}}
						</select>
					</td>
					<td>附加价格：
						<!-- 注意：这里附加价格是一个数组 -->
						<input type="text" name="attr_price[]" value="{{$vv['attr_price']}}" />
					</td>
					<td><span class="btn btn-success add-spec">增加规格</span></td>
				</tr>
				{{endforeach}}
				{{endif}}
			</table>
			{{endforeach}}

			<table class="table table-hover">
				<tr>
					<th colspan="2" style="text-align: center; background: #f5f5f5;">基本信息</th>
				</tr>
				<tr>
					<td style="width:200px;">所属品牌</td>
					<td>
						<select name="brand_brand_id" class="form-control w200">
							<option value="">-请选择-</option>
							{{foreach from="$brandData" value="$v"}}
							<option value="{{$v['brand_id']}}" {{if value=" $oldData['brand_brand_id'] eq $v['brand_id'] "}} selected="selected" {{endif}}>{{$v['brand_name']}}</option>
							{{endforeach}}
						</select>
					</td>
				</tr>
				<tr>
					<td style="width:200px;">商品名称</td>
					<td>
						<input id="goods_name" class="form-control w900" type="text" name="goods_name" value="{{$oldData['goods_name']}}">
					</td>
				</tr>
				<tr>
					<td style="width:200px;">库存</td>
					<td><input id="goods_number" class="form-control w900" type="text" name="goods_number" value="{{$oldData['goods_number']}}"></td>
				</tr>
				<tr>
					<td style="width:200px;">单位</td>
					<td><input id="unit" name="unit" class="form-control w200" type="text" value="{{$oldData['unit']}}"></td>
				</tr>
				<tr>
					<td style="width:200px;">市场价</td>
					<td><input id="market_price" name="market_price" class="form-control w200" type="text" value="{{$oldData['market_price']}}"></td>
				</tr>
				<tr>
					<td style="width:200px;">商城价</td>
					<td><input id="shop_price" name="shop_price" class="form-control w200" type="text" value="{{$oldData['shop_price']}}"></td>
				</tr>
				<tr>
					<td style="width:200px;">点击次数</td>
					<td><input id="click_count" name="click_count" class="form-control w200" type="text" value="{{$oldData['click_count']}}"></td>
				</tr>
				<tr>
					<td style="width:200px;">排序</td>
					<td><input id="sort_order" name="sort_order" class="form-control w200" type="text" value="{{$oldData['sort_order']}}"></td>
				</tr>
			</table>
	
			<table class="table table-hover">
				<tr>
					<td colspan="3" style="text-align: left;">
						<p class="btn btn-primary btn-sm fw">列表图</p>
					</td>
				</tr>
				<tr>
					<td style="line-height: 20px;" class="w200">上传图片</td>
					<td class="w200">
						<div lab="uploadFile">
						    <input id="f1" type="file" multiple="true" name="list_pics">
						    <span>类型: *.jpg,*.png 大小: 2000KB 数量: 1</span>
						     <!-- 上传代码 开始 -->
						    <script type="text/javascript">
						        $(function() {//alert(1);
						            $('#f1').uploadify({
						                'formData'     : {//POST数据
						                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
						                },
						                'fileTypeDesc' : '上传文件',//上传描述
						                'fileTypeExts' : '*.jpg;*.png',
						                'swf'      : '{{__PUBLIC__}}/uploadify/uploadify.swf',
						                'uploader' : '{{U('upload_list')}}',
						                'buttonText':'选择文件',
						                'fileSizeLimit' : '2000KB',
						                'uploadLimit' : 1,//上传文件数
						                'width':65,
						                'height':25,
						                'successTimeout':10,//等待服务器响应时间
						                'removeTimeout' : 0.2,//成功显示时间
						                'onUploadSuccess' : function(file, data, response) {
											//转为json
						                    data=$.parseJSON(data);
						                    //获得图片地址
						                    var imageUrl = data.url;
						                    var li="<li path='"+data.path+"' url='"+data.url+"'><img width='100' height='100' src='"+imageUrl+"'/><input type='hidden' name='list_pic' value='"+data.path+"'/></li>";
						                    $("#uploadList1 ul").prepend(li);
						                }
						            });
					                $('#closepic').click(function(){
					                    $(this).css({display:"none"});
					                    $(this).parent('li').remove();
					                    $('#pichid').css({display:"block"});
					
					                });
					                $('#closepic').hover(function(){
					                    $(this).css({background:"#aaa",cursor:"pointer"});
					                },function (){
					                    $(this).css({background:"#ddd"});
					                });
						        });
						    </script>
						    <!-- 上传代码  结束-->
						</div>
					</td>
					<td>
					    <div id="uploadList1">
					        <ul>
					        	{{if value="$oldData['list_pic'] !='' "}}				        	
				                    <li style='height:100px;display:inline-block;list-style: none;padding:0 10px;position:relative;'>
				                        <img style="height:100px;border:1px solid #ccc;border-radius:5px;" src="{{$oldData['list_pic']}}" width="100" alt="">
				                        <span id="closepic" style="display:block;line-height:10px;font-size:10px;background:#ddd;color:#000;border-radius:5px;position:absolute;width=100px;height:10px;top:-5px;right:-5px;">X</span>
				                        <input type="hidden" name="list_pic" value="{{$oldData['list_pic']}}">
				                    </li>
					        	{{endif}}
					        </ul>
					    </div>
					</td>
				</tr>
			</table>
			<table class="table table-hover">
				<tr>
					<td colspan="3" style="text-align: left;">
						<p class="btn btn-primary btn-sm fw">商品图册</p>
					</td>
				</tr>
				<tr>
					<td style="line-height: 20px;" class="w200">上传图片</td>
					<td class="w200">
						<div lab="uploadFile">
						    <input id="f2" type="file" multiple="true" name="goods_img">
						    <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
						    <script type="text/javascript">
						        $(function() {
						            $('#f2').uploadify({
						                'formData'     : {//POST数据
						                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
						                },
						                'fileTypeDesc' : '上传文件',//上传描述
						                'fileTypeExts' : '*.jpg;*.png',
						                'swf'      : '{{__PUBLIC__}}/uploadify/uploadify.swf',
						                'uploader' : '{{U('upload_most')}}',
						                'buttonText':'选择文件',
						                'fileSizeLimit' : '2000KB',
						                'uploadLimit' : 20,//上传文件数
						                'width':65,
						                'height':25,
						                'successTimeout':10,//等待服务器响应时间
						                'removeTimeout' : 0.2,//成功显示时间
						                'onUploadSuccess' : function(file, data, response) {
											//转为json
						                    data=$.parseJSON(data);
						                    //获得图片地址
						                    var imageUrl = data.url;
						                    var li="<li path='"+data.path+"' url='"+data.url+"'><img width='100' height='100' src='"+imageUrl+"'/><input type='hidden' name='goods_img[]' value='"+data.path+"'/></li>";
						                    $("#uploadList2 ul").prepend(li);
						                }
						            });
					               $('.closebigpic').click(function(){
					                    $(this).css({display:"none"});
					                    $(this).parent('li').remove();
					
					                });
					                $('.closebigpic').hover(function(){
					                    $(this).css({background:"#aaa",cursor:"pointer"});
					                },function (){
					                    $(this).css({background:"#ddd"});
					                });
						        });
						    </script>
						</div>
					</td>
					<td>
					    <div id="uploadList2">
					        <ul>
					        	{{if value="$oldData['goods_img'] !='' "}}
					        	{{foreach from="$oldData['goods_img']" value="$v"}}
				                 <li style='height:100px;display:inline-block;list-style: none;padding:0 10px;position:relative;'>
			                        <img style="height:100px;border:1px solid #ccc;border-radius:5px;" src="{{$v}}" alt="">
			                        <span class="closebigpic" style="display:block;line-height:10px;font-size:10px;background:#ddd;color:#000;border-radius:5px;position:absolute;width=10px;height:10px;top:-5px;right:-5px;">X</span>
			                        <input type="hidden" name="goods_img[]" value="{{$v}}">
			                    </li>
					        	{{endforeach}}
					        	{{endif}}
					        	
					        </ul>
					    </div>
					</td>
				</tr>
			</table>
			<table class="table table-hover">
				<tr>
					<td style="text-align: left;">
						<p class="btn btn-primary btn-sm fw">商品详细</p>
					</td>
				</tr>
				<tr>
					<td>
						<!--调用百度编辑器-->
						<script id="goods_desc" name="goods_desc" type="text/plain" style="width:100%;height:260px;">{{$oldData['goods_desc']}}</script>
					    <script>
					        var ue = UE.getEditor('goods_desc');
					    </script>
					</td>
				</tr>
			</table>
			<table class="table table-hover">
				<tr>
					<td style="text-align: left;">
						<p class="btn btn-primary btn-sm fw">售后服务</p>
					</td>
				</tr>
				<tr class="info">
					<td>
						<!--调用百度编辑器-->
						<script id="goods_service" name="goods_service" type="text/plain" style="width:100%;height:260px;">{{$oldData['goods_service']}}</script>
					    <script>
					        var ue = UE.getEditor('goods_service');
					    </script>
					</td>
				</tr>
			</table>
			<input type="hidden" name='form_fid' value=''/>
			<button class="btn btn-primary btn-block" type="submit"> 确定修改 </button>
		</form>
	</body>
</html>
